package spc.webos.queue;

import java.util.Hashtable;
import org.apache.log4j.Logger;
import spc.webos.util.StringX;

public abstract class AbstractReceiverThread extends AccessThread {
	protected byte[] messageId;
	protected IOnMessage onMessage;
	protected Hashtable props;

	public AbstractReceiverThread() {
		this.rw = 0;
	}

	public String getStartInfo() {
		return getName() + ", qname:" + this.qname + ", cnn:" + this.props;
	}

	public void execute() throws Exception {
		String qName = (!StringX.nullity(this.qname)) ? this.qname
				: this.bufferName;
		startThreadLog();

		Object obj = receive(qName);
		if (obj == null)
			return;
		if (this.onMessage == null)
			this.log.warn("onMessage is null!!!");
		else
			this.onMessage.onMessage(obj, (AccessTPool) this.pool, this);
	}

	public abstract Object receive(String paramString) throws Exception;

	public Hashtable getProps() {
		return this.props;
	}

	public void setProps(Hashtable props) {
		this.props = props;
	}

	public IOnMessage getOnMessage() {
		return this.onMessage;
	}

	public void setOnMessage(IOnMessage onMessage) {
		this.onMessage = onMessage;
	}

	public byte[] getMessageId() {
		return this.messageId;
	}

	public void setMessageId(byte[] messageId) {
		this.messageId = messageId;
	}

	public void setMessageId(String messageId) {
		this.messageId = messageId.getBytes();
	}
}
